<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @category   Hamania
 * @package    Hamania_CashOnRelay
 * @copyright  Copyright (c) 2008-2009 Andrej Sinicyn, Mik3e
 * @copyright  Copyright (c) 2010 Hamania Medien GmbH & Co. KG (http://www.hamania-medien.de)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

class Hamania_CashOnRelay_Block_Order_Totals_Cor extends Mage_Core_Block_Abstract
{

   public function initTotals()
    {       
        $parent = $this->getParentBlock();
        $this->_order   = $parent->getOrder();
        if($this->_order->getCorFee()){
            $cor = new Varien_Object();
            $cor->setLabel($this->__('Cash on Relay'));
            $cor->setValue($this->_order->getCorFee());
            $cor->setBaseValue($this->_order->getBaseCorFee());
            $cor->setCode('cor_fee');

            if (Mage::helper('cashonrelay')->displayCorBothPrices()){
                $cor->setLabel($this->__('Cash on Relay fee (Excl.Tax)'));

                $corIncl = new Varien_Object();
                $corIncl->setLabel($this->__('Cash on Relay fee (Incl.Tax)'));
                $corIncl->setValue($this->_order->getCorFee()+$this->_order->getCorTaxAmount());
                $corIncl->setBaseValue($this->_order->getBaseCorFee()+$this->_order->getBaseCorTaxAmount());
                $corIncl->setCode('cor_fee_incl');
                
                $parent->addTotalBefore($cor,'tax');
                $parent->addTotalBefore($corIncl,'tax');
            }elseif(Mage::helper('cashonrelay')->displayCorFeeIncludingTax()){                
                $cor->setValue($this->_order->getCorFee()+$this->_order->getCorTaxAmount());
                $cor->setBaseValue($this->_order->getBaseCorFee()+$this->_order->getBaseCorTaxAmount());                
                $parent->addTotalBefore($cor,'tax');
            }else{
                $parent->addTotalBefore($cor,'tax');
            }
        }

        return $this;        
    }

}